package com.qfedu.meidijiaju.controller;

import com.qfedu.meidijiaju.entity.Follow;
import com.qfedu.meidijiaju.service.FollowService;
import com.qfedu.meidijiaju.common.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "粉丝模块接口",description = "关于粉丝模块的接口")
@RestController
public class FollowController {

    @Autowired
    private FollowService followService;

    /**
     * 查询全部粉丝个数
     * @param uid
     * @return
     */
    @ApiOperation(value = "获取当前用户的粉丝,需要前端传递uid")
    @RequestMapping(value = "/follow/queryFuns",method = RequestMethod.GET)
    public ResponseData<List<Follow>> queryFuns(int uid) {
       int count = followService.queryCountFuns(String.valueOf(uid));
       List<Follow> result = followService.queryFuns(uid);
        ResponseData<List<Follow>> responseData = new ResponseData<>();

       if (count != 0) {
           responseData.setCode(0);
           responseData.setCount(count);
           responseData.setData(result);

       }
       return responseData;

    }

    /**
     * 查询当前用户所关注的人
     *
     * @param uid
     * @return
     */
    @ApiOperation(value = "获取当前用户所关注的人,需要前端传递uid")
    @RequestMapping(value = "/follow/queryFollowers",method = RequestMethod.GET)
    public ResponseData<List<Follow>> queryFollowers(int uid) {
        int count = followService.queryCountFollowers(String.valueOf(uid));
        List<Follow> result = followService.queryFollowers(uid);
//        System.out.println("result = " + result);
        System.out.println("count = " + count);

        ResponseData<List<Follow>> responseData = new ResponseData<>();

        if (count != 0) {
            responseData.setCode(0);
            responseData.setCount(count);
            responseData.setData(result);
        }
        return responseData;

    }

    /**
     * 添加当前用户的关注
     * @param follow 前端传递 uid 当前用户id，aid 所需关注用户id
     * @return
     */
    @ApiOperation("添加关注")
    @RequestMapping(value = "/addFollower",method = RequestMethod.GET)
    public ResponseData<String> addFollower(Follow follow) {
        ResponseData<String> responseData = new ResponseData<>();
        boolean addFollower = followService.addFollower(follow);
        if (addFollower) {
            responseData.setCode(0);
            responseData.setMsg("关注成功");
        }

        return responseData;
    }

    /**
     * 取消当前用户的关注
     * @param follow 前端传递 uid 当前用户id，aid 所需取关用户id
     * @return
     */
    @ApiOperation("取消关注")
    @RequestMapping(value = "/deleteFollower",method = RequestMethod.GET)
    public ResponseData<String> deleteFollower(Follow follow) {
        ResponseData<String> responseData = new ResponseData<>();
        boolean deleteFollower = followService.deleteFollower(follow);
        if (deleteFollower) {
            responseData.setCode(0);
            responseData.setMsg("取关成功");
        }

        return responseData;
    }


}
